//
//  MBProfileNavView.m
//  Meboo
//
//  Created by kyo on 2024/3/13.
//

#import "MBProfileNavView.h"
@interface MBProfileNavView ()
@property (nonatomic, strong) UIButton *leftBtn;

@property (nonatomic, strong) UILabel *titleLab;

@property (nonatomic, strong) UIButton *rightBtn;
@end

@implementation MBProfileNavView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public


#pragma mark - Action

- (void)rightAction {
    if (self.rightBlock) {
        self.rightBlock();
    }
}

- (void)leftAction {
    if (self.leftBlock) {
        self.leftBlock();
    }
//    [self.currentViewController.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.mas_equalTo(MBHeightScale(-8));
    }];
    
    [self addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(20));
        make.centerY.equalTo(self.titleLab);
        make.width.height.mas_equalTo(MBHeightScale(20));
    }];
    
    [self addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(MBWidthScale(-20));
        make.centerY.equalTo(self.titleLab);
        make.width.mas_equalTo(MBWidthScale(55));
        make.height.mas_equalTo(MBHeightScale(26));
    }];

}

#pragma mark - Setter && Getter
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [[UIButton alloc] init];
        [_leftBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_leftBtn setImage:ImageWithName(@"back_arrow_black") forState:0];
        [_leftBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [[UIButton alloc] init];
        _rightBtn.layer.cornerRadius = MBHeightScale(26/2);
        [_rightBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_rightBtn setBackgroundColor:HEXS(@"B92176")];
        [_rightBtn setTitle:@"Done" forState:0];
        [_rightBtn setTitleColor:UIColor.whiteColor forState:0];
        _rightBtn.titleLabel.font = PDSemiBoldScale(15);
        [_rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = PDSemiBoldScale(20);
        _titleLab.textColor = HEXS(@"333333");
        _titleLab.text = @"Edit profile";
    }
    return _titleLab;
}

@end
